package com.naive.imperative.view;

import java.util.Iterator;

import android.util.SparseArray;

public class IterableSparceArray<E> extends SparseArray<E> implements
		Iterable<E> {
	
	public IterableSparceArray() {
		super();
	}

	public IterableSparceArray(int initialCapacity) {
		super(initialCapacity);
	}

	public Iterator<E> iterator() {
		return new IndexIterator();
	}

	private class IndexIterator implements Iterator<E> {
		private int index;

		public boolean hasNext() {
			return size() - 1 > index;
		}

		public E next() {
			return valueAt(index++);
		}

		public void remove() {
			IterableSparceArray.this.remove(keyAt(index));
		}
	}
}
